package dto

import "math"

type PageCondition struct {
	PageIndex int `form:"pageIndex" json:"pageIndex"`
	PageSize int `form:"pageSize" json:"pageSize"`
}

type PageResult struct {
	PageCondition
	Data interface{} `json:"data"`
	ItemCount int64 `json:"itemCount""`
	TotalPage int `json:"totalPage"`
}

func (page PageCondition) GetPageSizeAndOffset() (int,int)  {
	offset := (page.PageIndex-1)*page.PageSize
	return page.PageSize,offset
}

func (page PageCondition)GetPageResult(totalItemCount int,data interface{}) *PageResult  {
	fl := float64(totalItemCount)/float64(page.PageSize)
	totalPage := math.Ceil(fl)
	result := PageResult{
		PageCondition:page,
		Data:data,
		TotalPage:int(totalPage),
		ItemCount:int64(totalItemCount)}
	return &result
}